<%--
  Created by IntelliJ IDEA.
  User: 邱华英
  Date: 2022/10/10
  Time: 20:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@page import="java.util.List" %>
<%@page import="java.util.Map" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<html>
<head>
    <title>管理员通知</title>
    <link rel="stylesheet" href="/css/base.css">
    <link rel="stylesheet" href="/css/common.css">
    <link rel="stylesheet" href="/css/readeradmin.css">
    <link rel="stylesheet" href="/css/booksearch.css">
    <link rel="stylesheet" href="/css/index.css">
    <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
    <style type="text/css">
        .fengye{
            border: 1px solid;
            display: inline;
            padding: 8px 16px;
        }

        span{
            color: aliceblue;
        }
        table{

            width: 980px;
        }


        td{

            overflow: hidden;

        }

        #fff{
            float: left;
            margin-left: 50px;
            width:693px;
            height: 44px;
            border: 1px solid black;
            position: relative;
        }

        #sss {
            float: left;
            height: 41px;
            width: 100px;
            text-align: center;
        }

        #ttt {
            float: left;
            width: 510px;
            height: 41px;
            padding-left: 10px;
            line-height: 41px;
        }

        #iii {
            /* float: right; */
            position: absolute;
            top: 0;
            left: 611px;
            width: 80px;
            height: 41px;
            background-color: #2d241d;
            font-size: 16px;
            color: #fff;
        }
        .tupian img {
            float: right;
            width: 980px;
            height: 465px;
        }

        .minyan {
            float: left;
            width: 100%;
            height: 163px;
            margin-top: 12px;
            background-color: green;
            text-align: center;
            font-size: 20px;
            font-weight: bold;
            line-height: 163px;
            color: #fff;
            background: rgba(0, 0, 0, 0.7);
        }
        .hide{
            display: none;
        }
        .c1{
            position: fixed;
            top:0;
            bottom: 0;
            left:0;
            right: 0;
            background: rgba(0,0,0,.5);
            z-index: 2;
        }
        .c2{
            background-color: white;
            position: fixed;
            width: 400px;
            height: 220px;
            top: 50%;
            left: 50%;
            z-index: 3;
            margin-top: -150px;
            margin-left: -200px;
            font-size: 15px;
        }
<%--  <title>通知</title>--%>
<%--  <style type="text/css">--%>
    /*  li{*/
    /*      border: 1px solid;*/
    /*      display: inline;*/
    /*      padding: 8px 16px;*/
    /*  }*/
    /*.c1{*/
    /*  position: fixed;*/
    /*  top:0;*/
    /*  bottom: 0;*/
    /*  left:0;*/
    /*  right: 0;*/
    /*  background: rgba(0,0,0,.5);*/
    /*  z-index: 2;*/
    /*}*/
    /*.c2{*/
    /*  background-color: white;*/
    /*  position: fixed;*/
    /*  width: 400px;*/
    /*  height: 330px;*/
    /*  top:50%;*/
    /*  left: 50%;*/
    /*  z-index: 3;*/
    /*  margin-top: -150px;*/
    /*  margin-left: -200px;*/
    /*}*/

    /*.hide{*/
    /*  display: none;*/
    /*}*/
    #receive{
      display: none;
    }
    .anniu{
        width: 70px;
        height: 25px;
        border: 1px solid black;

        font-size: 15px;

    }
  </style>
</head>
<body>
<%
    String contextPath = request.getSession().getServletContext().getContextPath();
%>
<section class="shortcut">
    <div class="w">
        <div class="fl">
            <ul>
                <li>图书管理系统！&nbsp;</li>
                <li>
                    <a href="index.html">请登录</a> &nbsp;
                    <a href="#" class="style-red">通知管理</a>
                </li>
            </ul>
        </div>
        <div class="fr">
            <ul>
                <li class="arrow-icon">我的消息</li>
                <li>|</li>
                <li class="arrow-icon"> <a href="<%=contextPath%>/admin/">退出</a></li>
            </ul>
        </div>
    </div>
</section>
<!-- 头部模块 -->
<header class="header w">
    <!-- logo -->
    <div class="logo">
        <h1>
            <a href="index.html" title="图书管理系统">人类进步的阶梯</a>
        </h1>
    </div>



</header>
<nav class="nav">
    <div class="w">
        <div class="dropdown">
            <div class="dt"> <a href="aindex.html">首页</a> </div>
            <div class="dd">
                <ul>
                    <li><a href="<%=contextPath%>/admin/User/">用户管理</a> </li>
                    <li><a href="<%=contextPath%>/admin/book/">图书管理</a> </li>
                    <li><a href="<%=contextPath%>/admin/borrow/">图书借阅管理</a> </li>

                    <li><a href="<%=contextPath%>/admin/inform/all/">通知</a></li>
                    <li><a href="<%=contextPath%>/admin/adminPCenter/">个人中心</a> </li>

                </ul>
            </div>
        </div>
<%--        <form  id="fff"   action="<%=contextPath%>/admin/User/select" method="post">--%>
<%--            <select id="sss"    name="select">--%>
<%--                <option value="zhanghao">账号</option>--%>
<%--                <option value="username">用户名</option>--%>
<%--            </select>--%>
<%--            <input  id="ttt"   type="text" name="text" value="用户名"/>--%>
<%--            <input id="iii"    type="submit" value="搜索"/><br><br>--%>
<%--        </form>--%>
        <form  id="fff" action="<%=contextPath%>/admin/inform/select" method="post" onsubmit="return testEmpty()">
            <select  id="sss" name="select">
                <option value="publisher">发布人账号</option>
                <option value="receiver">接收人账号</option>
            </select>
            <input id="ttt" type="text" name="text" id="text" placeholder="请输入账号"/>
            <input  id="iii" type="submit" value="搜索"/><br><br>
        </form>

    </div>
</nav>
<%--<button onclick="Show()">添加通知</button><br>--%>
<%--<button onclick="javascrtpt:window.location.href='<%=contextPath%>/admin/inform/all/'">all</button>--%>
<%--<button onclick="javascrtpt:window.location.href='<%=contextPath%>/admin/inform/public/'">public</button>--%>
<%--<button onclick="javascrtpt:window.location.href='<%=contextPath%>/admin/inform/private/'">private</button><br>--%>
<div class="w">
    <div class="main">
        <button class="anniu" onclick="Show()">添加通知</button><br>
        <button class="anniu"  onclick="javascrtpt:window.location.href='<%=contextPath%>/admin/inform/all/'">all</button>
        <button class="anniu"  onclick="javascrtpt:window.location.href='<%=contextPath%>/admin/inform/public/'">public</button>
        <button class="anniu"  onclick="javascrtpt:window.location.href='<%=contextPath%>/admin/inform/private/'">private</button><br>
        <table  id="mainTable" align="center " border="1 " cellpadding="1px " cellspacing="2px " width="980px "  ;>
            <thead class="biaoge ">
            <tr>
                <th>通知编号</th>
                <th>通知类型</th>
                <th>发布的管理员用户名</th>
                <th>发布的管理员账号</th>
                <th>接收的用户名</th>
                <th>接收的用户账号</th>
                <th>发布时间</th>
                <th>发布内容</th>
            </tr>
            </thead>

<%--    <form  id="fff" action="<%=contextPath%>/admin/inform/select" method="post" onsubmit="return testEmpty()">--%>
<%--      <select  id="sss" name="select">--%>
<%--        <option value="publisher">发布人账号</option>--%>
<%--        <option value="receiver">接收人账号</option>--%>
<%--      </select>--%>
<%--      <input id="ttt" type="text" name="text" id="text" placeholder="请输入账号"/>--%>
<%--      <input  id="iii" type="submit" value="搜索"/><br><br>--%>
<%--    </form>--%>
<%--    <button onclick="Show()">添加通知</button><br>--%>
<%--    <button onclick="javascrtpt:window.location.href='<%=contextPath%>/admin/inform/all/'">all</button>--%>
<%--    <button onclick="javascrtpt:window.location.href='<%=contextPath%>/admin/inform/public/'">public</button>--%>
<%--    <button onclick="javascrtpt:window.location.href='<%=contextPath%>/admin/inform/private/'">private</button><br>--%>
<%--    <table border="1px">--%>
<%--      <th>通知编号</th>--%>
<%--      <th>通知类型</th>--%>
<%--      <th>发布的管理员用户名</th>--%>
<%--      <th>发布的管理员账号</th>--%>
<%--      <th>接收的用户名</th>--%>
<%--      <th>接收的用户账号</th>--%>
<%--      <th>发布时间</th>--%>
<%--      <th>发布内容</th>--%>
        <%
            List<Map<String, Object>> informs = (List<Map<String, Object>>) request.getAttribute("inform");
            if(informs != null){
                for(Map<String,Object>inform : informs){

        %>
        <tr>
            <td><%=inform.get("informId")%></td>
            <td><%=inform.get("informName")%></td>
            <td><%=inform.get("adminName")%></td>
            <td><%=inform.get("azhanghao")%></td>
            <td><%=inform.get("userName")%></td>
            <td><%=inform.get("zhanghao")%></td>
            <td><%=inform.get("sendTime")%></td>
            <td><%=inform.get("information")%></td>
        </tr>
        <%}%>
        <%}%>
    </table><br><br>
        <div>
            <li class="fengye"><a onclick="deleteYeshu()"><<</a></li>
            <li class="fengye">第<label name="yeshu" id="yeshu">${yeshu}</label>页</li>
            <li class="fengye"><a onclick="addYeshu()">>></a></li>
        </div>



    <div id="shade" class="c1 hide"></div>

    <div id="modal" class="c2 hide">
      <form>
        <h2>添加通知</h2>
        <label>通知类型</label>
        <select onchange="change()" id="select">
        <c:if test="${not empty informType}">
             <c:forEach items="${informType}" var="informTypes">
                 <option value ="${informTypes.informId}">${informTypes.informName}</option>
            </c:forEach>
        </c:if>
        </select><br>
        <div id="receive">
          <label>接收人：</label><input type="text" id="receive1"/><br>
        </div>
        <label>内容：</label><textarea  rows="5" cols="50" id="textarea1"></textarea><br>
        <input type="button" value="确定发送" id="add"/><input type="reset" value="重置" /><input type="button" value="取消" onclick="Hide()"/>
      </form>
    </div>

    </div>
</div>
<div class="w ">
    <div class="minyan">

        好好建设图书馆，全心全意为读者服务！

    </div>
</body>
    <script type="text/javascript">
      function Show(){
        document.getElementById('shade').classList.remove('hide');
        document.getElementById('modal').classList.remove('hide');
      }
      function Hide(){
        document.getElementById('shade').classList.add('hide');
        document.getElementById('modal').classList.add('hide');
      }
      function change(){
        var obj = document.getElementById("select"); //定位id
        var index = obj.selectedIndex; // 选中索引
        if(index==1){
          var receiver = document.getElementById("receive");
          receiver.style.display="block";
        }else if(index=2){
          var receiver = document.getElementById("receive");
          receiver.style.display="none";
        }
      }

      function addYeshu(){
          var yeshu1 = document.getElementById("yeshu");
          var t = $("#search").text();
          window.location.href="<%=contextPath%>/admin/inform/${search}/add?yeshu="+yeshu1.innerText;
      }
      function deleteYeshu(){
          var yeshu1 = document.getElementById("yeshu");
          window.location.href="<%=contextPath%>/admin/inform/${search}/delete?yeshu="+yeshu1.innerText;
      }

      $(function (){
          $("#add").click(function (){
              var select = $("#select").val();
              var receive = $("#receive1").val();
              var textarea = $("#textarea1").val();
              // alert(textarea);
                  $.ajax({
                      type:"post",
                      url:"<%=contextPath%>/admin/inform/add",
                      data:{
                          "select":select,
                          "receive":receive,
                          "textarea":textarea,
                      },
                      success:function (msg){
                          if(msg==true){
                              alert("发送成功！")
                          }else{
                              alert("发送失败")
                          }
                      }
                  })



          })
      })

      function testEmpty(){
          var test1 = document.getElementById("text").value;
          var reg=/^[1-9]/;
          if(test1.length > 0 && reg.test(test1)){
              return true;
          }else{
              alert("空，或者为非纯数字")
              return false;
          }
      }

      // $(document).ready(function() {
      //     $(".search1").click(function () {
      //         $("#search").html($(this).html());
      //         alert($("#search").text());
      //     })
      // })
    </script>
</html>
